﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HFUTCourseSimulation.Kernel {

    /// <summary>
    /// 消息的类型
    /// </summary>
    public enum ReporterKind {
        Info,
        Warning,
        Error
    }

    /// <summary>
    /// 被记录的消息条目
    /// </summary>
    public class ReporterEntry {
        public ReporterEntry(ReporterKind kind, string message) {
            this.Kind = kind;
            this.Message = message;
        }

        public ReporterKind Kind { get; private set; }
        public string Message { get; private set; }
    }

    /// <summary>
    /// 用于记录模拟过程中的消息（例如错误，警告等）
    /// </summary>
    public class Reporter : IEnumerable<ReporterEntry> {
        public Reporter() {
            entries = new List<ReporterEntry>();
            hasError = false;
        }

        private List<ReporterEntry> entries;
        private bool hasError;

        /// <summary>
        /// 检查过程中是否有错误类型的消息被记录
        /// </summary>
        /// <returns>如果有则返回true，否则为false</returns>
        public bool HasError() {
            return hasError;
        }

        /// <summary>
        /// 记录一条提示消息
        /// </summary>
        /// <param name="message">消息内容</param>
        public void Info(string message) {
            entries.Add(new ReporterEntry(ReporterKind.Info, message));
        }
        /// <summary>
        /// 记录一条警告消息
        /// </summary>
        /// <param name="message">消息内容</param>
        public void Warning(string message) {
            entries.Add(new ReporterEntry(ReporterKind.Warning, message));
        }
        /// <summary>
        /// 记录一条错误消息
        /// </summary>
        /// <param name="message">消息内容</param>
        public void Error(string message) {
            this.hasError = true;
            entries.Add(new ReporterEntry(ReporterKind.Error, message));
        }
        /// <summary>
        /// 重置记录器状态
        /// </summary>
        public void Clear() {
            entries.Clear();
            hasError = false;
        }

        public IEnumerator<ReporterEntry> GetEnumerator() {
            return entries.GetEnumerator();
        }
        IEnumerator IEnumerable.GetEnumerator() {
            return GetEnumerator();
        }
    }

}
